


#include <iostream>
#include <cassert>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class Solution
{
public:
    int evalRPN1(vector<string>& tokens)
    {
        vector<int> v;

        for (const auto& e : tokens)
        {
            if ("+" == e || "-" == e || "*" == e || "/" == e)
            {
                int a = v.back();
                v.pop_back();

                if ("+" == e)
                {
                    v.back() += a;
                }
                else if ("-" == e)
                {
                    v.back() -= a;
                }
                else if ("*" == e)
                {
                    v.back() *= a;
                }
                else
                {
                    v.back() /= a;
                }
            }
            else
            {
                v.push_back(stoi(e));
            }
        }

        return v[0];
    }

    int evalRPN(vector<string>& tokens)
    {
        vector<int> v;

        for (const auto& e : tokens)
        {
            if (e.size() > 1 || isdigit(e[0]))
            {
                v.push_back(stoi(e));
            }
            else
            {
                char op = e[0];
                int a = v.back();
                v.pop_back();

                switch (op)
                {
                case '+':
                    v.back() += a;
                    break;
                case '-':
                    v.back() -= a;
                    break;
                case '*':
                    v.back() *= a;
                    break;
                case '/':
                    v.back() /= a;
                    break;
                default:
                    assert(false);
                    break;
                }
            }
        }

        return v[0];
    }

    bool isUnique1(string astr)
    {
        int cnt[26] = { 0 };

        for (const auto& e : astr)
        {
            if (cnt[e - 'a'])
                return false;
            ++cnt[e - 'a'];
        }

        return true;
    }

    bool isUnique2(string astr)
    {
        int n = astr.size();
        if (n > 26)
            return false;

        sort(astr.begin(), astr.end());

        for (int i = 0; i < n - 1; ++i)
        {
            if (astr[i + 1] == astr[i])
                return false;
        }

        return true;
    }

    bool isUnique3(string astr)
    {
        if (astr.size() > 26)
            return false;

        int bitmap = 0, index = 0;

        for (const auto& e : astr)
        {
            index = e - 'a';

            if ((bitmap >> index) & 1u)
                return false;
            bitmap |= 1u << index;
        }

        return true;
    }

    bool isUnique4(string astr)
    {
        unordered_set<char> hash;

        for (const auto& e : astr)
        {
            auto it = hash.insert(e);
            if (it.second == false)
                return false;
        }

        return true;
    }
};

void Test1()
{
    vector<string> tokens = { "4","13","5","/","+" };

    Solution().evalRPN(tokens);
}

int main()
{
    Test1();

	return 0;
}